/*
SC
*/

#ifndef ShowFindUpdateSCC_H_
#define ShowFindUpdateSCC_H_
#include <string>
#include <algorithm>

using namespace std;
		
class ShowFindUpdateSCC
{
public:
	
	static Customer cust;
	static string cust_name;
	static vector<Cart_item> items;
	static vector<Product> prods;
	static vector<Category> cats;
	static vector<Cart> carts;
	static vector<Customer> custs;
	//static vector<string> names;
	static vector<Customer> a;
	//static vector<Cart>cust_carts;
	//static vector<Cart_item>cust_items;
	//static void foo(){}
	
	ShowFindUpdateSCC(){}
	
	static void show(vector<Customer> custs)
	{		
		/*sort(names.begin(),names.end());
			
		for (int i=0; i<names.size() ; ++i)
		{
			for (int j=0; j<names.size() ; ++j)
			{
				if (custs[i].cust_name == names[j])
				{
					a[j] = custs[i];
				}
			}
		}*/
		
		for (int i=0 ; i<custs.size() ; ++i)//repeats for each line //RY I changed a to custs for now
		{
			cout 	<< custs[i].cust_name << " "
					<< '(' << custs[i].cust_id << "): "
					<< custs[i].addr.house << " "
					<< custs[i].addr.street << " "
					<< custs[i].addr.zip_code << endl;
		}	
		cout << endl;
	}
	
	static void find(vector<Customer> custs, vector<Cart_item> items, vector<Cart> carts, vector<Product> prods)
	{	
		vector<Cart>cust_carts;
		vector<Cart_item>cust_items;
		string cust_name= "";
		int cust_id = 0;
		double sales = 0;
		double add = 0;
		cout << "Which customer?\n> ";
		while (cin >> cust_name)
		{	
			for (int i=0 ; i<custs.size() ; ++i)
			{
				if (cust_name == custs[i].cust_name)
				{
					cust_id=custs[i].cust_id;
					break;
				}
			}
			if (cust_name == "") cout << "That customer is not in our database.";
			break;
		}
		cout << endl;
		
		for (int i=0 ; i<carts.size() ; ++i)
		{
			if (cust_id == carts[i].cust_id)
			{
				cust_carts.push_back(carts[i]);
			}
		}
		
		for (int i=0 ; i<cust_carts.size() ; ++i)
		{
			for (int j=0 ; j<items.size() ; ++j)
			{
				if (cust_carts[i].cart_id == items[j].cart_id)
				{
					cust_items.push_back(items[j]);
				}
			}
		}
		
		for (int i=0 ; i<cust_items.size() ; ++i)
		{
			for (int j=0 ; j<prods.size() ; ++j)
			{
				if (cust_items[i].prod_id == prods[j].prod_id)
				{
					add= cust_items[i].prod_qty * prods[j].prod_price;
					sales += add;
				}
			}
		}
		cout << "$ " << sales << endl;
	}
	
	//RY the parameter should be pointer because the method needs to change the vector
	//pay attention to its access using '->' not '.'
	static void update(vector<Customer> *custs) 
	{
		string cust_name= "";
		int house= 0;
		string street= "";
		int zip_code= 0;
		//int cust_id= (custs[custs->size()-1])->cust_id + 10;
		int cust_id = custs->at(custs->size()-1).cust_id + 10; //RY
		cout << "What is the customer's name?\n> ";
		cin >> cust_name;
		cout << "What is the customer's address? (e.g. 1234 main 56789)\n> ";
		cin >> house
			>> street
			>> zip_code;
		
		Address addr(house,street,zip_code);
		Customer cust(cust_id,cust_name,addr);
		custs->push_back(cust);
	}	
};

/*vector<Customer> ShowFindUpdateSCC::custs = vector<Customer>();
vector<string> ShowFindUpdateSCC::names = vector<string>();
vector<Customer> ShowFindUpdateSCC::a = vector<Customer>();
/*vector<Cart> ShowFindUpdateSCC::carts = vector<Cart>();
vector<Cart_item> ShowFindUpdateSCC::items = vector<Cart_item>();
vector<Product> ShowFindUpdateSCC::prods = vector<Product>();
//vector<Cart> ShowFindUpdateSCC::cust_carts = vector<Cart>();
//vector<Cart_item> ShowFindUpdateSCC::cust_items = vector<Cart_item>();
vector<Category> ShowFindUpdateSCC::cats = vector<Category>();*/


#endif //ShowFindUpdateSCC_H_
